package bit.chapter.onelevo;

import static org.junit.Assert.assertEquals;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.junit.Test;

public class ChapterTransferTest {

	@Test
	public void conver2HexStr() {
		assertEquals(Arrays.toString(charArr2IntArr("000000000000000000001000".toCharArray())), Arrays.toString(ChapterTransfer.hexToIntArr("000008")));
		assertEquals(Arrays.toString(charArr2IntArr("000000000000000000000010".toCharArray())), Arrays.toString(ChapterTransfer.hexToIntArr("000002")));
		assertEquals(Arrays.toString(charArr2IntArr("01000000".toCharArray())), Arrays.toString(ChapterTransfer.hexToIntArr("40")));
		assertEquals(Arrays.toString(charArr2IntArr(("000000000000000000000000000000000000000000000000000000000000"
				+ "00000000000000000000000000000000000010000000").toCharArray())), Arrays.toString(ChapterTransfer.hexToIntArr("00000000000000000000000080")));
	}
	
	@Test
	public void chapterNo() {
		List<Integer> listResult = new ArrayList<>();
		listResult.add(20);
		assertEquals(listResult.toString(), ChapterTransfer.chapterNoIntArr(charArr2IntArr("000000000000000000001000".toCharArray()),0).toString());
		
		listResult.clear();
		listResult.add(22);
		assertEquals(listResult.toString(), ChapterTransfer.chapterNoIntArr(charArr2IntArr("000000000000000000000010".toCharArray()),0).toString());
		
		listResult.clear();
		listResult.add(1);
		assertEquals(listResult.toString(), ChapterTransfer.chapterNoIntArr(charArr2IntArr("01000000".toCharArray()),0).toString());
		
		listResult.clear();
		listResult.add(496);
		assertEquals(listResult.toString(), ChapterTransfer.chapterNoIntArr(charArr2IntArr(("00000000000000000000000000000000000000000000000"
				+ "000000000000000000000000000000000000000000000000010000000").toCharArray()),400).toString());
	}

	private int [] charArr2IntArr(char[] charArray) {
		int [] intArray = new int [charArray.length];
		for(int i = 0;i < charArray.length;i++){
			intArray[i] = Integer.parseInt(charArray[i] + "");
		}
		return intArray;
	}

	@Test
	public void chapterId() {
		String bookInfoPath = "D:\\projects\\asiaDir\\mission\\数媒\\割接\\章节表解码\\zhangjiexuhao(1).csv";
		ChapterTransfer.initBookMap(bookInfoPath);
		
		assertEquals("371843480",ChapterTransfer.bookMap.get("371843458").get("20"));
		assertEquals("385196495",ChapterTransfer.bookMap.get("385196471").get("22"));
		assertEquals("410234127",ChapterTransfer.bookMap.get("405459727").get("1"));
		assertEquals("448146253",ChapterTransfer.bookMap.get("441026949").get("496"));
		
	}
	
}
